import type { MetadataRoute } from 'next';

import { locales } from '@/i18n/config';

export default function sitemap(): MetadataRoute.Sitemap {
  const baseUrl = process.env.NEXT_PUBLIC_APP_URL || 'https://your-domain.com';

  const routes = ['', '/about', '/contact', '/products', '/dashboard'];

  const sitemap: MetadataRoute.Sitemap = [];

  // 为每个语言生成URL
  locales.forEach(locale => {
    routes.forEach(route => {
      const url =
        locale === 'zh' ? `${baseUrl}${route}` : `${baseUrl}/${locale}${route}`;

      sitemap.push({
        url,
        lastModified: new Date(),
        changeFrequency: 'weekly',
        priority: route === '' ? 1 : 0.8,
        alternates: {
          languages: locales.reduce(
            (acc, loc) => {
              acc[loc] =
                loc === 'zh'
                  ? `${baseUrl}${route}`
                  : `${baseUrl}/${loc}${route}`;
              return acc;
            },
            {} as Record<string, string>
          ),
        },
      });
    });
  });

  return sitemap;
}
